import { getCategoryAPI } from "@/apis/category";
import { ref, onMounted,watch } from "vue";
import { useRoute } from "vue-router";

//封装分类数据业务相关代码
export function useCategory(){
    //获取数据
const categoryData = ref({});
const route = useRoute();

const getCategory = async (id) => {
  // 如何在setup中获取路由参数 useRoute() -> route 等价于this.$route
  const res = await getCategoryAPI(route.params.id);
  categoryData.value = res.result;
};
onMounted(() => {
  getCategory()
}),
watch(route,()=>{getCategory()}) 
return{
categoryData
}
}